<%@ page language="java" pageEncoding="UTF-8" contentType="text/html;charset=UTF-8"%>
<%@ include file="/common/header.jsp" %>

<script src="${ctx}/assets/js/jquery.validate.js"></script>
<!--[if lte IE 9]>
  <link rel="stylesheet" href="${ctx}/assets/css/ace-ie.css" />
<![endif]-->

<script>
var scripts = [null, null];
$('.page-content-area').ace_ajax('loadScripts', scripts, function() {
	initButtons();
});


function initButtons() {
	if ("${operFlag}" == "detail") {
		$("#btnRModify").show();
		$("#btnRSave").hide();
		$("#btnRDelete").hide();	
		$("#btnRCancle").hide();
		$("#btnRClose").show();
		$("#btnRMenuModify").show();
		disabledAll("roleDetailForm");
	} else {
		$("#orgId").attr("disabled", false);
		$("#btnRModify").hide();
		$("#btnRSave").show();
		$("#btnRDelete").hide();
		$("#btnRCancle").hide();
		$("#btnRClose").show();	
		$("#btnRMenuModify").hide();
		$("#role_id").hide();
		$("#role_createUser").hide();
		$("#role_createTime").hide();
		$("#role_updateUser").hide();
		$("#role_updateTime").hide();
	}
	//只有未启用的状态才显示删除按钮
	if($("#roleStatus").val()!="0"){
		$("#btnRDelete").hide();
	} 
	 

}



function save() { 
	enabledAll("roleDetailForm");
	$("#roleDetailForm").validate({
	    errorElement: 'div',
	    errorClass: 'help-block',
	    focusInvalid: false,
	    rules: {
	       roleName: {
	          required: true
	       },
	       roleLevel: {
	          required: true
	       },
	       roleStatus: {
	    	 required: true
	       },
	    },
	
	    messages: {
	    	roleName: {
	           required: "角色名称不能为空！"
	        }, 
	        roleLevel: {
	           required: "角色等级不能为空！"
	        }, 
	        roleStatus: {
	           required: "角色状态不能为空！"
	        }        
	    },
	
	    highlight: function (e) {
	        $(e).closest('.form-group').removeClass('has-info').addClass('has-error');
	    },
	
	    success: function (e) {
	        $(e).closest('.form-group').removeClass('has-error').addClass('has-info');
	        $(e).remove();
	    },
	
	    errorPlacement: function (error, element) {
	        error.insertAfter(element.parent());
	    }
	});	
	
	if ($("#roleDetailForm").valid() == false) {
			return;
	}
	if($("#roleId").val()==""){
		$.ajax({
			url : "${ctx}/role/insert",
			async : false,
			data : $("#roleDetailForm").serialize(),
			type : "POST",
			dataType : "json",
			success: function(ret){	
				 if (ret[0] == "ok") {
					 alert(ret[1]);
					 $("#roleDetailIframe").dialog("close");
					 $("#roleList").load("${ctx}/role/list?temp="+new Date().getTime());
				  } else{
					  alert(ret[1]);
				  }				
			    },
			 error: function(ret){
				   alert(ret.responseText);
				   disabledAll("roleDetailForm");
			 }
		});	
	}else if($("#roleId").val()!=""){
		$.ajax({
			url : "${ctx}/role/update",
			async : false,
			data : $("#roleDetailForm").serialize(),
			type : "POST",
			dataType : "json",
		    success: function(ret){	
			  if (ret[0] == "ok") {
				  alert(ret[1]);
				  initButtons();
				  $("#roleDetailIframe").dialog("close");
				  $("#roleList").load("${ctx}/role/list?temp="+new Date().getTime());
			   } else{
				   alert(ret[1]);
			   }				
		    },
		    error: function(ret){
			    alert(ret.responseText);
			    disabledAll("roleDetailForm");
		    }
		});	
	}
}
function menuModify(){
	
	var roleId=$("#roleId").val();

	$("#roleMenus").load("${ctx}/role/getRoleMenuDetailInfo?roleId="+roleId);
   	$('#roleMenus').dialog('open'); 
   	$("#roleDetailIframe").dialog("close");
}
//角色详细信息

function modify(){
	
	$("#btnRModify").hide();
	$("#btnRSave").show();
	$("#btnRDelete").hide();
	$("#btnRCancle").show();
	$("#btnRClose").show();
	$("#btnRMenuModify").hide();
	
	$("#roleName").attr("disabled",false);
	$("#roleLevel").attr("disabled",false);
	$("#roleStatus").attr("disabled",false);
	$("#roleDesc").attr("disabled",false);
	$("#systemFlag").attr("disabled",false)
	
}

function cancle(){
	if($("#roleId").val()==""){
		var iscancle=window.confirm("确定取消？");
		if(iscancle==true){
			$('#roleDetailIframe').hide();
		}
		else{
			return;
		}
	}
	if($("#roleId").val()!=""){
		var iscancle=window.confirm("确定取消修改？");
		if(iscancle==true){
			$("#roleName").attr("value",$("#rolename").val());
			$("#roleLevel").attr("value",$("#rolelevel").val());
			$("#roleStatus").attr("value",$("#rolestatus").val());
			$("#roleDesc").attr("value",$("#roledesc").val());
		}
		else{
			return;
		}
		initButtons();
		$("#menuModify").show();
		$("#modify").show();
	}
	
	$("#roleDetailForm")[0].reset();
}
	
</script>
<div class="row">
	<div class="col-xs-12">	
	<form  id="roleDetailForm" name="roleDetailForm" class="form-horizontal" role="form">
			<div class="row">
		   
		   <div class="form-group col-sm-12" id="role_id">
					<label class="col-sm-3 control-label no-padding-right" for="roleId">角色编号：</label>
					<div class="col-sm-9">
						<input type="text" class="col-xs-10 col-sm-8"  name="roleId" id="roleId" value="${roleInfo.roleId}" maxlength="40" readonly  title="角色编号出系统自动生成"/>
					</div>
		   </div>
		   
		   <div class="form-group col-sm-12">
					<label class="col-sm-3 control-label no-padding-right" for="roleName">角色名称：<font color="red">*</font></label>
					<div class="col-sm-9">
					  <div class="clearfix">
						<input type="text" class="col-xs-10 col-sm-8"  name="roleName" id="roleName" value="${roleInfo.roleName}" maxlength="40" />
					  </div>
					</div>
		   </div>
		   
		   <div class="form-group col-sm-12">
					<label class="col-sm-3 control-label no-padding-right" for="roleLevel">角色等级：<font color="red">*</font></label>
					<div class="col-sm-9">
					   <div class="clearfix">				
					    <select class="col-xs-10 col-sm-8" id="roleLevel" name="roleLevel">
				
					    	 <hw:dictOption dictType="D00030" value="${roleInfo.roleLevel}" nullLable="no"/>
						</select>
                       </div>
	
					</div>
		   </div>
				
		   <div class="form-group col-sm-12">
					<label class="col-sm-3 control-label no-padding-right" for="roleStatus">角色状态：<font color="red">*</font></label>
					<div class="col-sm-9">
					  <div class="clearfix">
					    <select class="col-xs-10 col-sm-8" id="roleStatus" name="roleStatus">
					
					      <hw:dictOption dictType="D00023" value="${roleInfo.roleStatus}" nullLable="no"/>
						</select>
					  </div>
					</div>
		   </div>
		   <div class="form-group col-sm-12">
					<label class="col-sm-3 control-label no-padding-right" for="systemFlag">所属系统：<font color="red">*</font></label>
					<div class="col-sm-9">
					  <div class="clearfix">
					    <select class="col-xs-10 col-sm-8" id="systemFlag" name="systemFlag">
					
					      <hw:dictOption dictType="KHWH00015" value="${roleInfo.systemFlag}" nullLable="no"/>
						</select>
					  </div>
					</div>
		   </div>	
		 <%--   <div class="form-group col-sm-12" id="role_createUser">
					<label class="col-sm-3 control-label no-padding-right" for="createUser">创建人：</label>
					<div class="col-sm-9">
						<input type="text" class="col-xs-10 col-sm-8"  name="createUser" id="createUser" value="<hw:userName userId='${roleInfo.createBy}' />"  disabled/>
					</div>
		   </div>
		   
		   <div class="form-group col-sm-12" id="role_createTime">
					<label class="col-sm-3 control-label no-padding-right" for="createTime">创建时间：</label>
					<div class="col-sm-9">
						<input type="text" class="col-xs-10 col-sm-8"  name="createTime" id="createTime" value="${roleInfo.createDate}" disabled/>
					</div>
		   </div>
		   
		    <div class="form-group col-sm-12" id="role_updateUser">
					<label class="col-sm-3 control-label no-padding-right" for="updateUser">修改人：</label>
					<div class="col-sm-9">
						<input type="text" class="col-xs-10 col-sm-8"  name="updateUser" id="updateUser" value="<hw:userName userId='${roleInfo.updateBy}' />" disabled/>
					</div>
		   </div>
		   
		    <div class="form-group col-sm-12" id="role_updateTime">
					<label class="col-sm-3 control-label no-padding-right" for="updateTime">修改时间：</label>
					<div class="col-sm-9">
						<input type="text" class="col-xs-10 col-sm-8"  name="updateTime" id="updateTime" value="${roleInfo.updateDate}" disabled/>
					</div>
		   </div> --%>
		   
		   
		   <div class="form-group col-sm-12">
					<label class="col-sm-3 control-label no-padding-right" for="roleDesc">角色描述：</label>
					<div class="col-sm-9">
					<textarea  id="roleDesc" class="col-xs-12 col-sm-12" name="roleDesc" onpropertychange="if(value.length>400) value=value.substr(0,400)" class="smallArea" name="remark" cols="80" rows="3">${roleInfo.roleDesc}</textarea>
					</div>
		   </div>	
		   
		</div>
	</form>	
</div>
</div>
